package com.kun.index.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kun.index.entity.Blog;
import com.kun.index.entity.Comment;
import com.kun.index.mapper.CommentMapper;
import com.kun.index.service.CommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 评论表 服务实现类
 * </p>
 *
 * @author kunkun
 * @since 2024-03-12
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {

    @Autowired
    private CommentMapper commentMapper;

    @Override
    public Integer insertComment(Comment comment) {
        return  commentMapper.insert(comment);
    }

    @Override
    public List<Comment> queryCommentsByBlogId(Integer blogId) {
        QueryWrapper<Comment> wrapper = new QueryWrapper<>();
        wrapper.eq("blogId",blogId);
        return commentMapper.selectList(wrapper);
    }

    @Override
    public Comment queryCommentById(Integer pId) {
        return commentMapper.selectById(pId);
    }
}
